package io.gitee.hechenl.datamultitrans.mqtt;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.*;

@AllArgsConstructor
@Slf4j
public class CallBackDefaultImpl implements MqttCallback {

    private MqttConsumer mqttConsumer;

    @Override
    public void connectionLost(Throwable cause) {
        log.warn("MqttCallback connectionLost", cause);
    }

    @Override
    public void messageArrived(String topic, MqttMessage message) {
        if (mqttConsumer != null && topic.equals(mqttConsumer.getTopic())) {
            mqttConsumer.consumer(message);
        }
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken token) {
        log.debug("MqttCallback deliveryComplete");
    }
}
